#! /bin/bash
if [ -n "$APTPROXY" ]; then
ainsl -a /etc/apt/apt.conf.d/02proxy "Acquire::http::Proxy \"$APTPROXY\";"
ainsl  /etc/apt/apt.conf.d/02proxy 'Acquire::https::proxy "DIRECT";'
else
    rm -f $target/etc/apt/apt.conf.d/02proxy
fi
echo "DPkg::Progress-Fancy "true";" > $target/etc/apt/apt.conf.d/01color
echo "APT::Color "true";" >> $target/etc/apt/apt.conf.d/01color
echo force-unsafe-io > $target/etc/dpkg/dpkg.cfg.d/unsafe-io

$ROOTCMD apt-get update -y
$ROOTCMD apt-get install -y apt-transport-https

#kernel modules for zfs
ainsl -a /etc/dkms/spl.conf 'POST_INSTALL="scripts/dkms.postbuild -a ${arch} -k ${kernelver} -v ${PACKAGE_VERSION} -n ${PACKAGE_NAME} -t ${dkms_tree}"'
fcopy /etc/dkms/zfs.conf

ainsl -a /etc/apt/apt.conf.d/03download 'Acquire::Queue-Mode "access";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::Retries "3";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::CompressionTypes::Order "lzma";'
ainsl /etc/apt/apt.conf.d/03download 'Acquire::ForceIPv4 "true";'
ainsl /etc/apt/apt.conf.d/70debconf 'APT::ExtractTemplates::TempDir "/var/tmp";'
fcopy /etc/apt/sources.list

#sed -i 's/^#deb\ http:\/\/mirrors.aliyun.com/deb\ http:\/\/mirrors.aliyun.com/' $target/etc/apt/sources.list

if ifclass CUDA; then
    sed -i 's/^#deb\ https:\/\/nvidia.github.io/deb\ https:\/\/nvidia.github.io/' $target/etc/apt/sources.list
fi
# you may want to add i386 arch to amd64 hosts
#if ifclass AMD64; then
#    $ROOTCMD dpkg --add-architecture i386
#fi
cp -f /etc/apt/trusted.gpg.d/*.gpg $target/etc/apt/trusted.gpg.d/
